import { defHttp } from "/@/utils/http/axios";
import { ScoreModel, TeachingRecordModel } from "/@/api/model/practicalModel";
import { PageParams, PageResult, PageWithId } from "/@/api/model/pageModel";

enum Api {
  GetTeachingRecordPage = "/teachingRecord/page",
  SaveTeachingRecord = "/teachingRecord/save",
  UpdateTeachingRecord = "/teachingRecord/update",
  RemoveTeachingRecord = "/teachingRecord/remove",
  SetTeachingRecordScore = "/teachingRecord/setScore",
  GetTeachingRecordScore = "/teachingRecord/getScore",
}

export const getTeachingRecordPageApi = (params: PageParams) =>
  defHttp.get<PageResult<TeachingRecordModel>>({ url: Api.GetTeachingRecordPage, params });

export const getTeachingRecordPageByIdApi = (params: PageWithId) =>
  defHttp.get<PageResult<TeachingRecordModel>>({
    url: `${Api.GetTeachingRecordPage}/${params.userId}`,
    params,
  });

export const saveTeachingRecordApi = (params: TeachingRecordModel) =>
  defHttp.post<void>({ url: Api.SaveTeachingRecord, params });

export const updateTeachingRecordApi = (params: TeachingRecordModel) =>
  defHttp.put<void>({ url: Api.UpdateTeachingRecord, params });

export const removeTeachingRecordApi = (recordId: number) =>
  defHttp.delete<void>({ url: `${Api.RemoveTeachingRecord}/${recordId}` });

export const setTeachingRecordScoreApi = (
  userId: number,
  recordId: number,
  schScore: number,
  univScore: number,
) =>
  defHttp.put<void>({
    url: `${Api.SetTeachingRecordScore}/${userId}/${recordId}`,
    params: { schScore, univScore },
  });

export const getTeachingRecordScoreApi = (userId: number, recordId: number) =>
  defHttp.get<ScoreModel>({ url: `${Api.GetTeachingRecordScore}/${userId}/${recordId}` });
